package com.ruoyi.pack.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.pack.mapper.PackContainerOperationLogMapper;
import com.ruoyi.pack.domain.PackContainerOperationLog;
import com.ruoyi.pack.service.IPackContainerOperationLogService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.DateUtils;

/**
 * 器具操作记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Service
public class PackContainerOperationLogServiceImpl implements IPackContainerOperationLogService 
{
    @Autowired
    private PackContainerOperationLogMapper packContainerOperationLogMapper;

    /**
     * 查询器具操作记录
     * 
     * @param logId 器具操作记录主键
     * @return 器具操作记录
     */
    @Override
    public PackContainerOperationLog selectPackContainerOperationLogByLogId(Long logId)
    {
        return packContainerOperationLogMapper.selectPackContainerOperationLogByLogId(logId);
    }

    /**
     * 查询器具操作记录列表
     * 
     * @param packContainerOperationLog 器具操作记录
     * @return 器具操作记录
     */
    @Override
    public List<PackContainerOperationLog> selectPackContainerOperationLogList(PackContainerOperationLog packContainerOperationLog)
    {
        return packContainerOperationLogMapper.selectPackContainerOperationLogList(packContainerOperationLog);
    }

    /**
     * 查询器具操作记录列表（带搜索条件）
     * 
     * @param params 搜索参数
     * @return 器具操作记录集合
     */
    @Override
    public List<PackContainerOperationLog> selectPackContainerOperationLogListWithParams(Map<String, Object> params)
    {
        return packContainerOperationLogMapper.selectPackContainerOperationLogListWithParams(params);
    }

    /**
     * 新增器具操作记录
     * 
     * @param packContainerOperationLog 器具操作记录
     * @return 结果
     */
    @Override
    public int insertPackContainerOperationLog(PackContainerOperationLog packContainerOperationLog)
    {
        packContainerOperationLog.setCreateTime(DateUtils.getNowDate());
        packContainerOperationLog.setCreateBy(SecurityUtils.getUsername());
        return packContainerOperationLogMapper.insertPackContainerOperationLog(packContainerOperationLog);
    }

    /**
     * 修改器具操作记录
     * 
     * @param packContainerOperationLog 器具操作记录
     * @return 结果
     */
    @Override
    public int updatePackContainerOperationLog(PackContainerOperationLog packContainerOperationLog)
    {
        packContainerOperationLog.setUpdateTime(DateUtils.getNowDate());
        packContainerOperationLog.setUpdateBy(SecurityUtils.getUsername());
        return packContainerOperationLogMapper.updatePackContainerOperationLog(packContainerOperationLog);
    }

    /**
     * 批量删除器具操作记录
     * 
     * @param logIds 需要删除的器具操作记录主键
     * @return 结果
     */
    @Override
    public int deletePackContainerOperationLogByLogIds(Long[] logIds)
    {
        return packContainerOperationLogMapper.deletePackContainerOperationLogByLogIds(logIds);
    }

    /**
     * 删除器具操作记录信息
     * 
     * @param logId 器具操作记录主键
     * @return 结果
     */
    @Override
    public int deletePackContainerOperationLogByLogId(Long logId)
    {
        return packContainerOperationLogMapper.deletePackContainerOperationLogByLogId(logId);
    }

    /**
     * 获取筛选条件选项
     * 
     * @return 筛选条件选项
     */
    @Override
    public Map<String, Object> getFilterOptions()
    {
        Map<String, Object> options = new HashMap<>();
        
        // 获取仓库选项
        List<Map<String, Object>> warehouseOptions = packContainerOperationLogMapper.selectWarehouseOptions();
        options.put("warehouseOptions", warehouseOptions);
        
        // 获取操作人员选项
        List<Map<String, Object>> operatorOptions = packContainerOperationLogMapper.selectOperatorOptions();
        options.put("operatorOptions", operatorOptions);
        
        // 获取操作类型选项
        Map<String, String> operationTypeOptions = new HashMap<>();
        operationTypeOptions.put("1", "新增");
        operationTypeOptions.put("2", "定位器绑定");
        operationTypeOptions.put("3", "定位器解绑");
        operationTypeOptions.put("4", "清洗");
        operationTypeOptions.put("5", "折叠整理");
        operationTypeOptions.put("6", "装箱");
        operationTypeOptions.put("7", "拆箱");
        operationTypeOptions.put("8", "封存");
        operationTypeOptions.put("9", "解封");
        operationTypeOptions.put("10", "维修");
        operationTypeOptions.put("11", "检查");
        options.put("operationTypeOptions", operationTypeOptions);
        
        return options;
    }

    /**
     * 记录器具操作日志
     * 
     * @param containerId 器具ID
     * @param operationType 操作类型
     * @param operationDetail 操作详情
     * @param warehouseId 仓库ID
     * @param remark 备注
     */
    @Override
    public void recordOperationLog(Long containerId, String operationType, String operationDetail, Long warehouseId, String remark)
    {
        PackContainerOperationLog log = new PackContainerOperationLog();
        log.setContainerId(containerId);
        log.setOperationType(operationType);
        log.setOperationDetail(operationDetail);
        log.setWarehouseId(warehouseId);
        log.setRemark(remark);
        log.setOperatorId(SecurityUtils.getUserId());
        log.setOperationTime(new Date());
        log.setCreateBy(SecurityUtils.getUsername());
        log.setCreateTime(new Date());
        
        packContainerOperationLogMapper.insertPackContainerOperationLog(log);
    }
} 